package com.zyk.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import entity.Product;
@org.springframework.web.bind.annotation.RestController
public class RestController {
	//private final static String REST_URL_PREFIX="http://localhost:8001";
	//开启ribbon负载均衡就可以通过服务名进行调用
	private final static String REST_URL_PREFIX="http://microservice-product";
	@Autowired
	private RestTemplate restTemplate;
	@RequestMapping(value="/consumer/product/add")
	public boolean add(Product product) {
		return restTemplate.postForObject(REST_URL_PREFIX+"/product/add", product, Boolean.class);
	}
	@RequestMapping(value= "/consumer/product/get/{id}")
	public Product get(@PathVariable(value="id")Long id) {
		return restTemplate.getForObject(REST_URL_PREFIX+"/product/get/"+id, Product.class);
	}
	@RequestMapping(value="/consumer/product/list")
	public List<Product> list(){
		return restTemplate.getForObject(REST_URL_PREFIX+"/product/list", List.class);
	}
}
